#!/bin/bash

LIB_DIR=$(cd $(dirname "$0") && pwd)

echo "lib directory " $LIB_DIR

source ${LIB_DIR}/lib-centos7

source ${LIB_DIR}/lib-centos8
source ${LIB_DIR}/lib-ubuntu16

env_set()
{
    hostnamectl set-hostname $HOSTNAME
    HOSTNAME=`hostname -s`
#Set $HOSTNAME
    if ! fgrep -qwe "$HOSTNAME" /etc/hosts; then

        sudo sed -i '$a '"$HOST_IP"' '"$HOSTNAME"'' /etc/hosts

    else

        sudo sed -i 's/^.*'"$HOSTNAME"'.*$/'"$HOST_IP"' '"$HOSTNAME"'/' /etc/hosts

    fi
#Set other nodes in /etc/hosts
    for key in  ${!SIBLINGS[*]}; do
        echo " $key ${SIBLINGS[$key]}"
        sed -i '$a '"${SIBLINGS[$key]}"' '"$key"'' /etc/hosts
    done
    
    #centos7 firewall stop
   if [[ $is_cent7 -eq 1 ]]  ;then
       echo "Install openstack Rocky on centos7"
       cent7_env
   elif [[ $is_cent8 -eq 1 ]] ; then
       echo "Install openstack U On centos8"
       cent8_env
      
   fi

}


install_netfilter()
{

   if [[ $is_ub16 -eq 1 ]] ; then
       echo "Install Openstack Queen on Ubuntu16"
       ub16_env
       
   fi
}


install_chrony()
{
   if [[ $is_cent7 -eq 1 ]]  ;then
       echo "Install openstack Chrony on centos7"
       centos7_chrony
   elif [[ $is_cent8 -eq 1 ]] ; then
      echo "Install openstack  ussuri On centos8"
       centos8_chrony
      
   elif [[ $is_ub16 -eq 1 ]] ; then
      echo "Install Openstack Queen on Ubuntu16"
       ub16_chrony
       
   fi
}

install_openstack_pkg()
{
   if [[ $is_cent7 -eq 1 ]]  ;then
       echo "Install openstack Rocky on centos7"
       function_centos7_rocky
   elif [[ $is_cent8 -eq 1 ]] ; then
     echo "Install openstack Ussuri On centos8"
       function_centos8_ussuri
      
   elif [[ $is_ub16 -eq 1 ]] ; then
      echo "Install Openstack QUEENs on Ubuntu16"
       function_ub16_queen
       
   fi
}

install_mariadb()
{
   if [[ $is_cent7 -eq 1 ]]  ;then
       echo "Install maridb on centos7"
       function_centos7_mariadb
   elif [[ $is_cent8 -eq 1 ]] ; then
       echo "Install openstack maridb On centos8"
       function_centos8_mariadb
       
   elif [[ $is_ub16 -eq 1 ]] ; then
        echo "Install Openstack maridb on Ubuntu16"
       function_ub16_mariadb
      
   fi
}

install_rabbitmq()
{
   if [[ $is_cent7 -eq 1 ]]  ;then
       echo "Install rabbitmq  on centos7"
       centos7_install_rabbitmq
   elif [[ $is_cent8 -eq 1 ]] ; then
       echo "Install rabbitmq  On centos8"
       centos8_install_rabbitmq
       
   elif [[ $is_ub16 -eq 1 ]] ; then
       echo "Install rabbitmq  on Ubuntu16"
       function_ub16_rabbitmq
      
   fi
}
install_memcache()
{
   if [[ $is_cent7 -eq 1 ]]  ;then
       echo "Install memcache  on centos7"
      centos7_install_memcache
   elif [[ $is_cent8 -eq 1 ]] ; then
       echo "Install memcache On centos8"
       centos8_install_memcache
      
   elif [[ $is_ub16 -eq 1 ]] ; then
       echo "Install memcache  on Ubuntu16"
       function_ub16_memcache
      
   fi
}


install_etcd()
{
   if [[ $is_cent7 -eq 1 ]]  ;then
       echo "Install etcd on centos7"
       centos7_install_etcd
   elif [[ $is_cent8 -eq 1 ]] ; then
       echo "Install etcd On centos8"
       centos8_install_etcd
       
   elif [[ $is_ub16 -eq 1 ]] ; then
        echo "Install etcd on Ubuntu16"
       function_ub16_etcd
      
   fi
}

install_keystone()
{
   if [[ $is_cent7 -eq 1 ]]  ;then
       echo "Install openstack keystone on centos7"
       function_centos7_keystone
   elif [[ $is_cent8 -eq 1 ]] ; then
        echo "Install openstack keystone On centos8.3"
       function_centos8_keystone
      
   elif [[ $is_ub16 -eq 1 ]] ; then
       echo "Install Openstack keystone on Ubuntu16"
       function_ub16_keystone
      
   fi
}

install_glance()
{
   if [[ $is_cent7 -eq 1 ]]  ;then
       echo "Install openstack glance on centos7"
        function_centos7_glance
   elif [[ $is_cent8 -eq 1 ]] ; then
        echo "Install openstack glance On centos8"
       function_centos8_glance
      
   elif [[ $is_ub16 -eq 1 ]] ; then
       echo "Install Openstack glance on Ubuntu16"
       function_ub16_glance
      
   fi
}

install_placement()
{
    if [[ $is_cent8 -eq 1 ]] ; then
	centos8_placement
    fi

}

install_controller_nova()
{
   if [[ $is_cent7 -eq 1 ]]  ;then
       echo "Install openstack nova on centos7"
       function_centos7_nova_for_controller
   elif [[ $is_cent8 -eq 1 ]] ; then
       echo "Install openstack nova On centos8"
       function_centos8_nova_for_controller
      
   elif [[ $is_ub16 -eq 1 ]] ; then
       echo "Install Openstack nova on Ubuntu16"
       function_ub16_nova_for_controller
       
   fi
}

install_controller_neutron()
{
   if [[ $is_cent7 -eq 1 ]]  ;then
       echo "Install openstack neutron on centos7"
       function_centos7_neutron_for_controller
   elif [[ $is_cent8 -eq 1 ]] ; then
       echo "Install openstack neutron On centos8"
       function_centos8_neutron_for_controller
      
   elif [[ $is_ub16 -eq 1 ]] ; then
        echo "Install Openstack neutron on Ubuntu16"
       function_ub16_neutron_for_controller
      
   fi
}

install_dashboard()
{
   if [[ $is_cent7 -eq 1 ]]  ;then
       echo "Install openstack dashboard on centos7"
       function_centos7_dashboard
   elif [[ $is_cent8 -eq 1 ]] ; then
       echo "Install openstack dashboard On centos8"
       function_centos8_dashboard
      
   elif [[ $is_ub16 -eq 1 ]] ; then
       echo "Install Openstack dashboard on Ubuntu16"
       function_ub16_dashboard
      
   fi
}

install_compute_nova()
{
   if [[ $is_cent7 -eq 1 ]]  ;then
       echo "Install openstack nova-compute on centos7"
       install_centos7_nova_for_compute
   elif [[ $is_cent8 -eq 1 ]] ; then
       echo "Install openstack nova-compute On centos8"
       install_centos8_nova_for_compute
      
   elif [[ $is_ub16 -eq 1 ]] ; then
       echo "Install Openstack nova-compute on Ubuntu16"
       function_ub16_nova_for_compute
      
   fi
}

install_compute_neutron()
{
   if [[ $is_cent7 -eq 1 ]]  ;then
       echo "Install openstack compute-neutron on centos7"
       install_centos7_neutron_for_compute
   elif [[ $is_cent8 -eq 1 ]] ; then
       echo "Install openstack compute-neutron On centos8"
       install_centos8_neutron_for_compute
       
   elif [[ $is_ub16 -eq 1 ]] ; then
       echo "Install Openstack compute-neutron on Ubuntu16"
       function_ub16_neutron_for_compute
      
   fi
}
